package com.lanou.dllo.vc.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.lanou.dllo.vc.R;

import java.util.List;

/**
 * Created by dllo on 15/11/26.
 */
public class GridViewAdapter extends BaseAdapter{
    private List<String> imageViews;
    private Context context;
    private CallBackSmeil callBackSmeil;
    String imgname;


    public GridViewAdapter(Context context, List<String> imageViews) {
        this.context = context;
        this.imageViews = imageViews;

    }


    @Override
    public int getCount() {
        return imageViews != null && imageViews.size() > 0 ? imageViews.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return imageViews.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyViewHolder holder = null;
        if (convertView == null) {
            holder = new MyViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.emo_imageview, null);

            holder.emo_img = (ImageView) convertView.findViewById(R.id.emo_img);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }

//
        holder.positon = position;
                imgname = imageViews.get(position);
        int resId = context.getResources().getIdentifier(imgname, "mipmap", context.getPackageName());


        if (resId > 0) {

            holder.emo_img.setImageResource(resId);
        }

        holder.emo_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Log.i("lanou","----->>>"+imgname);
                imgname = imageViews.get(position);
                if (callBackSmeil != null) {
                    callBackSmeil.getEmotion(imgname);

                }
            }
        });



        return convertView;
    }



   public  class MyViewHolder implements CallBackSmeil {
        ImageView emo_img;
      public   int positon;

        @Override
        public void getEmotion(String emoname) {

        }
    }

    public void setCallBackSmeil(CallBackSmeil callBackSmeil) {
        this.callBackSmeil = callBackSmeil;
    }


}
